package com.hksj.ecm.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.common.core.model.Rest;
import com.hksj.ecm.dto.EnergyDeviceDTO;
import com.hksj.ecm.dto.EnergyHistoryDeviceDTO;
import com.hksj.ecm.service.EnergyDeviceService;
import com.hksj.ecm.vo.EnergyDeviceVO;
import com.hksj.ecm.vo.EnergyHistoryDeviceVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;


@Api(tags = "能耗监测-设备列表")
@RequestMapping("/api/energyDevice")
@RestController
public class EnergyDeviceController {

    @Autowired
    private EnergyDeviceService energyDeviceService;

    @ApiOperation(value = "能耗列表查询",response = EnergyDeviceVO.class)
    @PostMapping("/queryEnergyDeviceByPage")
    public Rest<Page<EnergyDeviceVO>> queryEnergyDeviceByPage(@RequestBody EnergyDeviceDTO dto){
        return Rest.ok(energyDeviceService.queryEnergyDeviceByPage(dto));
    }

    @ApiOperation(value = "设备历史记录",response = EnergyHistoryDeviceVO.class)
    @PostMapping("/queryEnergyHistoryDevice")
    public Rest<Page<EnergyHistoryDeviceVO>> queryEnergyHistoryDevice(@RequestBody @Valid EnergyHistoryDeviceDTO dto){
        return Rest.ok(energyDeviceService.queryEnergyHistoryDevice(dto));
    }

    @ApiOperation(value = "设备历史记录导出")
    @PostMapping("/exportEnergyHistoryDeviceInfo")
    public void exportEnergyHistoryDeviceInfo(@RequestBody EnergyHistoryDeviceDTO dto, HttpServletResponse response) throws Exception {
        energyDeviceService.exportEnergyHistoryDeviceInfo(dto,response);
    }

}
